package br.usp.ipq.extgwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.gwtext.client.widgets.HTMLPanel;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.QuickTipsConfig;
import com.gwtext.client.widgets.Toolbar;
import com.gwtext.client.widgets.ToolbarButton;
import com.gwtext.client.widgets.ToolbarMenuButton;
import com.gwtext.client.widgets.ToolbarTextItem;
import com.gwtext.client.widgets.Viewport;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.layout.AccordionLayout;
import com.gwtext.client.widgets.layout.HorizontalLayout;
import com.gwtext.client.widgets.layout.VerticalLayout;
import com.gwtext.client.widgets.menu.Adapter;
import com.gwtext.client.widgets.menu.CheckItem;
import com.gwtext.client.widgets.menu.ColorItem;
import com.gwtext.client.widgets.menu.ColorMenu;
import com.gwtext.client.widgets.menu.DateMenu;
import com.gwtext.client.widgets.menu.Item;
import com.gwtext.client.widgets.menu.Menu;
import com.gwtext.client.widgets.menu.MenuItem;
import com.gwtext.client.widgets.menu.TextItem;
import com.gwtext.client.widgets.menu.event.CheckItemListenerAdapter;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ExtGWTMenu implements EntryPoint {

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		Panel panel = new Panel();
		panel.setBorder(false);
		panel.setPaddings(15);
		Toolbar toolbar = new Toolbar();

		panel.setLayout(new VerticalLayout(15));

		Menu menu = new Menu();
		menu.setShadow(true);
		menu.setMinWidth(10);

		final CheckItemListenerAdapter listener = new CheckItemListenerAdapter() {
			public void onCheckChange(CheckItem item, boolean checked) {
				System.out.println("'" + item.getText() + "' is now "
						+ (checked ? "checked" : "unchecked"));
			}
		};

		CheckItem checkItem = new CheckItem();
		checkItem.setText("I like Ext");
		checkItem.setChecked(true);
		checkItem.addListener(listener);
		menu.addItem(checkItem);

		CheckItem checkItem2 = new CheckItem();
		checkItem2.setText("I also like GWT-Ext :)");
		checkItem2.setChecked(true);
		checkItem2.addListener(listener);
		menu.addItem(checkItem2);

		CheckItem checkItem3 = new CheckItem();
		checkItem3.setText("I donated");
		checkItem3.setChecked(false);
		checkItem3.addListener(listener);
		menu.addItem(checkItem3);

		menu.addSeparator();

		Menu submenu = new Menu();
		submenu.setShadow(true);
		submenu.setMinWidth(10);
		submenu.addItem(new TextItem(
				"<b class=\"menu-title\">Choose a Theme</b>"));

		CheckItem checkItem4 = new CheckItem();
		checkItem4.setText("Aero Glass");
		checkItem4.setChecked(true);
		checkItem4.setGroup("theme");
		checkItem4.addListener(listener);
		submenu.addItem(checkItem4);

		CheckItem checkItem5 = new CheckItem();
		checkItem5.setText("Vista Black");
		checkItem5.setGroup("theme");
		checkItem5.addListener(listener);
		submenu.addItem(checkItem5);

		CheckItem checkItem7 = new CheckItem();
		checkItem7.setText("Gray Theme");
		checkItem7.setGroup("theme");
		checkItem7.addListener(listener);
		submenu.addItem(checkItem7);

		CheckItem checkItem8 = new CheckItem();
		checkItem8.setText("Default Theme");
		checkItem8.setGroup("theme");
		checkItem8.addListener(listener);
		submenu.addItem(checkItem8);

		MenuItem menuItem = new MenuItem("Radio Options", submenu);
		MenuItem dateMenuItem = new MenuItem("Choose a Date", new DateMenu());
		MenuItem colorMenuItem = new MenuItem("Choose a Color", new ColorMenu());
		menu.addItem(menuItem);
		menu.addItem(dateMenuItem);
		menu.addItem(colorMenuItem);
		menu.addSeparator();

		Item item = new Item();
		item.setText("Dynamically added");

		TextField textField = new TextField();
		Adapter adapter = new Adapter(textField);
		menu.addItem(adapter);

		Item item2 = new Item("Disabled");
		item2.setDisabled(true);
		menu.addItem(item);
		menu.addItem(item2);

		ToolbarButton menuButton = new ToolbarButton("Button w/ Menu");
		menuButton.setMenu(menu);
		menuButton.setIconCls("bmenu");
		toolbar.addButton(menuButton);
		toolbar.addSeparator();

		Menu splitMenu = new Menu();
		Item bi = new Item();
		bi.setText("<b>Bold</b>");
		splitMenu.addItem(bi);

		Item ii = new Item();
		ii.setText("<i>Italic</i>");
		splitMenu.addItem(ii);

		Item ui = new Item();
		ui.setText("<u>Underline</u>");
		splitMenu.addItem(ui);

		splitMenu.addSeparator();

		Menu colorMenu = new Menu();
		colorMenu.addItem(new ColorItem());
		colorMenu.addSeparator();
		Item moreColors = new Item();
		moreColors.setText("More Colors...");
		colorMenu.addItem(moreColors);

		MenuItem colorMI = new MenuItem("Pic a Color", colorMenu);
		splitMenu.addItem(colorMI);
		Item excellent = new Item();
		excellent.setText("Excellent");
		splitMenu.addItem(excellent);

		ToolbarMenuButton button2 = new ToolbarMenuButton("Split Button",
				splitMenu);

		toolbar.addButton(button2);
		toolbar.addSeparator();

		ToolbarButton toggleButton = new ToolbarButton("Toggle Me");
		toggleButton.setEnableToggle(true);
		toggleButton.setPressed(true);
		QuickTipsConfig tipsConfig = new QuickTipsConfig();
		tipsConfig.setText("This is a quicktip with a title");
		tipsConfig.setTitle("Tip Title");
		toggleButton.setTooltip(tipsConfig);

		ToolbarButton iconOnly = new ToolbarButton();
		iconOnly.setIcon("images/add-feed.gif");
		iconOnly.setCls("x-btn-icon");
		iconOnly
				.setTooltip("<b>Quick Tips</b><br/>Icon only button with tooltip");

		toolbar.addButton(iconOnly);
		toolbar.addSeparator();
		toolbar.addButton(toggleButton);

		toolbar.addSeparator();
		ToolbarTextItem ti = new ToolbarTextItem("Text Item");
		toolbar.addItem(ti);

		Panel toolbarPanel = new Panel();
		toolbarPanel.setWidth(500);
		toolbarPanel.setHeight(400);
		toolbarPanel.setTopToolbar(toolbar);
		panel.add(toolbar);
		
		Panel accordionPanel = createAccordionPanel();
		accordionPanel.setTitle("Accordion Panel");
		accordionPanel.setHeight(400);
		accordionPanel.setWidth(200);
		
		Panel centerPanelOne = new HTMLPanel();  
	    centerPanelOne.setHtml("<p>Center Panel</p>");  
	    centerPanelOne.setTitle("Center");
	    centerPanelOne.setHeight(400);
	    centerPanelOne.setWidth(500);
	    
		Panel innerPanel=new Panel();
		innerPanel.setLayout(new HorizontalLayout(10));
		innerPanel.add(accordionPanel);
		innerPanel.add(centerPanelOne);

		panel.add(innerPanel);
		Viewport viewport = new Viewport(panel);
	}

	private Panel createAccordionPanel() {
		Panel accordionPanel = new Panel();
		accordionPanel.setLayout(new AccordionLayout(true));

		Panel panelOne = new Panel("Panel 1", "<p>Panel1 content!</p>");
		panelOne.setIconCls("settings-icon");
		accordionPanel.add(panelOne);

		Panel panelTwo = new Panel("Panel 2", "<p>Panel2 content!</p>");
		panelTwo.setIconCls("folder-icon");
		accordionPanel.add(panelTwo);

		Panel panelThree = new Panel("Panel 3", "<p>Panel3 content!</p>");
		panelThree.setIconCls("user-add-icon");
		accordionPanel.add(panelThree);

		return accordionPanel;
	}

}
